const fs = require('fs')
const { plot, Plot, stack, clear } = require('nodeplotlib')
const { data } = require('../data/data')

console.log(data)

Object.keys(data).forEach((key) => {
    console.log(key)
    let resarr = []
    data[key].arr.forEach((item) => {
        let { state, quilty, a } = data[key]
        let temp = Number(((state - item) * 40 / 1000 / a / quilty).toFixed(4))
        resarr.push(temp)
    })
    data[key].resarr = resarr;

    // 绘图
    let xs = [...Array(10).keys()]
    const aaa = [{
        x: xs,
        y: resarr,
        type: 'scatter'
    }]
    stack(aaa)
})

fs.writeFile('./message.json', JSON.stringify(data, '', '\t'), (err) => { 

    if(err) console.log('写文件操作失败');   
    else console.log('写文件操作成功');
  
});

plot()